﻿@using CodeGenerator
@using RazorLight
@using BXJG.Common;
@inherits TemplatePage<ExecuteContext>
@{
    DisableEncoding = true;//禁止html编码，因为我们是做代码生成器
}
@("@page") "/@(Model.Model.Name)"

@@using BXJG.Utils.Application.Share.GeneralTree
@@using @(Model.Model.ApplicationShareNamespace);

@@attribute [ReuseTabsPage(Title = "@Model.Model.DisplayName")]
@@attribute [Authorize(@Model.Model.PermissionNameGetConst)]

@@inherits TreeListBaseComponent<@Model.Model.DtoName, @Model.Model.ConditionName>

<Flex Gap="FlexGap.Small" Vertical Justify="FlexJustify.SpaceBetween">
    <Flex Gap="FlexGap.Small" Justify="FlexJustify.SpaceBetween">
         @@* 左侧 *@@
        <Flex Gap="FlexGap.Small">
            @@if (createIsGranted)
            {
                <Button Type="@@ButtonType.Primary" Icon="@@IconType.Outline.Plus" OnClick="BtnCreateClick" Disabled="IsBusy">新增</Button>
            }
            @@if(deleteIsGranted)
            {
                <Popconfirm Title="将删除已经的项及其所有子项，确定删除吗?"
                            OnConfirm="BtnDeleteClick">
                    <Button Type="@@ButtonType.Default" Icon="@@IconType.Outline.Clear" Danger Loading="isDeleting" Disabled="ShouldDisableDelete">删除</Button>
                </Popconfirm>
            }
        </Flex>
        @@* 右侧 *@@
        <Flex Gap="FlexGap.Small">
@foreach (var field in Model.Model.ConditionRangeFields)
{
    if(field.CSharpTypeIsDateTime){
            <RangePicker TValue="@(field.CSharpType)?[]" @@bind-Value="@field.ConditionRangeName" Placeholder=@@(new string[] { "开始@(field.DisplayName)", "结束@(field.DisplayName)" }) @(field.Width.IsNotNullOrWhiteSpaceBXJG()?$@"Width=""{field.Width}""":"") />
    }
    else if(field.CSharpTypeIsNumber){
            <AntDesign.InputNumber @@bind-Value="GetAllInput.@field.ConditionRangeMin" PlaceHolder="最小@(field.DisplayName)" @(field.NumberPrecision.HasValue?@$"Precision=""{field.NumberPrecision}""":"") @(field.Width.IsNotNullOrWhiteSpaceBXJG()?$@"Width=""{field.Width}""":"")/>
            <AntDesign.InputNumber @@bind-Value="GetAllInput.@field.ConditionRangeMax" PlaceHolder="最大@(field.DisplayName)" @(field.NumberPrecision.HasValue?@$"Precision=""{field.NumberPrecision}""":"") @(field.Width.IsNotNullOrWhiteSpaceBXJG()?$@"Width=""{field.Width}""":"")/>
    }
}
@foreach (var field in Model.Model.ConditionNormalFields)
{
            <Input @@bind-Value="GetAllInput.@field.Name" PlaceHolder="@(field.DisplayName)" @(field.Width.IsNotNullOrWhiteSpaceBXJG()?$@"Width=""{field.Width}""":"")/>
}
            <div style="width:15rem;">
                <Search Placeholder="@(string.Join("/", Model.Model.ConditionStringFields.Select(x=>x.DisplayName)))等关键字..." @@bind-Value="Keywords" OnChange="BtnSearchClick" AllowClear="true" ClassicSearchIcon="true" Disabled="IsBusy" />
            </div>
            <Tooltip Title="清空条件">
                <Button Type="@@ButtonType.Default" Icon="@@IconType.Outline.Clear" OnClick="BtnClearFilterClick" Disabled="IsBusy"></Button>
            </Tooltip>
            <Tooltip Title="刷新">
                <Button Type="@@ButtonType.Default" Icon="@@IconType.Outline.Reload" OnClick="BtnRefreshClick" Disabled="IsBusy"></Button>
            </Tooltip>
        </Flex>
    </Flex>

    @@* 不能定义key，不然无法刷新子节点 *@@
    <Table @@ref="table"
           TreeChildren="GetTreeChildren"
           TItem="@Model.Model.DtoName"
           Total="TotalCount"
           @@bind-SelectedRows="SelectedItems"
           OnChange="OnQuery"
           DataSource="Items"
           Loading="IsLoading"
           HidePagination="true"
           RowClassName="@@(r=>r.RowIndex%2==0?"even":"odd")"
           RemoteDataSource="true"
           OnRow="Row"
           
           Size="TableSize.Small"
           Bordered="true"
           ScrollY="76vh">
        <Selection Fixed="ColumnFixPlacement.Left"/>
        @@*表格树起码在antblazor0.19前不支持 Fixed="ColumnFixPlacement.Left" 另外树不支持排序 *@@
        <PropertyColumn Property="c=>c.DisplayName" ShowSorterTooltip="false" Sortable="true" Width="12rem"/>
@foreach (var field in Model.Model.NormalFields){
    @if(field.CSharpType=="bool"){
        <PropertyColumn Property="c=>c.@(field.Name)" ShowSorterTooltip="false" Width="5rem" Align="ColumnAlign.Center">
            <Switch @@bind-Value="@@context.@(field.Name)" Size="@@InputSize.Small" Disabled="true"></Switch>
        </PropertyColumn>
    }else{
        <PropertyColumn Property="c=>c.@(field.Name)" ShowSorterTooltip="false" @(field.Width.IsNullOrWhiteSpaceBXJG()?"":@$"Width=""{field.Width}""") @(field.Position==true?"":(field.FixedLeft==false?@"Align=ColumnAlign.Right":@"Align=""ColumnAlign.Center"""))/>        
    }
}

        <ActionColumn Title="操作" Width="240" Fixed="ColumnFixPlacement.Right" Align="ColumnAlign.Center">
            <span @@onclick:stopPropagation="true">
                <ButtonGroup Size="@@ButtonGroupSize.Small">
                    @@if (deleteIsGranted)
                    {
                    <Popconfirm Title="将删除此项及其所有子项，确定删除吗?" OnConfirm="()=>BtnDeleteItemClick(context)">
                        <Button Size="@@ButtonSize.Small" Danger="true" Loading="@@context.ExtensionData.IsDeleting">删除</Button>
                    </Popconfirm>
                    }
                    <Button  OnClickStopPropagation="true" Size="@@ButtonSize.Small" Type="@@ButtonType.Primary" OnClick="x=>BtnItemDetailClick(context)">详情</Button>

                   
                    @@if (createIsGranted)
                {
                    <Button OnClickStopPropagation="true"  Size="@@ButtonSize.Small" OnClick="x=>BtnAddSubClick(context.Id)">添加子节点</Button>
                }
                @@if (updateIsGranted)
                {
                    <Button OnClickStopPropagation="true"  Size="@@ButtonSize.Small" OnClick="x=>BtnItemEditClick(context)">修改</Button>
                }
                </ButtonGroup>
            </span>
        </ActionColumn>
    </Table>

</Flex>

@@{
    RenderFragment renderFragment =@@<Template>
        <SectionOutlet SectionName=@@($"{GetHashCode()}-create-btns") />
        <Button OnClick="BtnCloseCreateClick">关闭</Button>
    </Template>;
}
    <Modal DestroyOnClose="true" 
           Footer="renderFragment" 
           @@bind-Visible="isShowCreateDialog" 
           Draggable="true" 
           Width=@@("40vw")
           AfterClose="AfterCloseDialog"
           Class="frm-dal" >
    <TitleTemplate>
        <Icon Type="plus" Theme="IconThemeType.Outline" />
        新增@@(FuncName)
    </TitleTemplate>
    <ChildContent>
        <SectionOutlet SectionName="@@($"{GetHashCode()}-create-body" )" />
        <@(Model.Model.BlazorClientNamespace).Create OnAddEnd="AddEnd" ParentId="parentId"  Master="GetHashCode()"/>
    </ChildContent>
</Modal>

@@{
    RenderFragment renderFragment1 =@@<Template>
        <SectionOutlet SectionName=@@($"{GetHashCode()}-detail-update-btns") />
        <Button OnClick="BtnDetailUpdateCloseClick">关闭</Button>
    </Template>;
}
<Modal DestroyOnClose="true" 
       Footer="renderFragment1" 
       @@bind-Visible="isShowDetailUpdateDialog" 
       Draggable="true" 
       Width=@@("40vw")
       Class="frm-dal"
       AfterClose="AfterCloseDialog">
    <TitleTemplate>
        <SectionOutlet SectionName=@@($"{GetHashCode()}-detail-update-title") />
    </TitleTemplate>
    <ChildContent>
        <SectionOutlet SectionName=@@($"{GetHashCode()}-detail-update-body") />
        <@(Model.Model.BlazorClientNamespace).DetailUpdate Id="@@(detailUpdateId)" IsEdit="isEdit" OnDeleted="DetailDeleted" OnUpdated="DetailUpdated" Master="GetHashCode()"/>
    </ChildContent>
</Modal>